//
//  MoreTableViewCell.m
//  ChengHuiTong
//
//  Created by ypwl on 15/11/30.
//  Copyright © 2015年 张文权. All rights reserved.
//

#import "MoreTableViewCell.h"

#import "CLLockVC.h"

@implementation MoreTableViewCell{
    
    UIImageView*_headerImageView;
    
    UILabel*_nameLabel;
    
   
    
    NSString*_reuseIdentifier;
}

- (void)awakeFromNib {
    // Initialization code
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        _reuseIdentifier=reuseIdentifier;
        
        
        if ([reuseIdentifier isEqualToString:@"cell0"]) {
            
            _headerImageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, (60-40)/2, 40, 40)];
            
            _headerImageView.layer.cornerRadius = 20;
            
            _headerImageView.clipsToBounds = YES;
            
            [self.contentView addSubview:_headerImageView];
            
            _nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_headerImageView.frame)+15, (60-20)/2, 150, 20)];
            _nameLabel.tag =10;
            
            _nameLabel.textColor=UIColorFromString(@"#888888");
            
            _nameLabel.font=[UIFont boldSystemFontOfSize:15];

            [self.contentView addSubview:_nameLabel];
            
            
        }else if([reuseIdentifier isEqualToString:@"cell1"]){
            
            _gestureSwith=[[UISwitch alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-10-60, 5, 60, 30)];
            
            [_gestureSwith addTarget:self action:@selector(changeSwith:) forControlEvents:UIControlEventValueChanged];
            
            [self.contentView addSubview:_gestureSwith];
            
            
        }else if ([reuseIdentifier isEqualToString:@"cell2"]){
            
            _unReadLabel=[[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 30 - autoScaleW(30), (44-30)/2, 30, 30)];
            
            _unReadLabel.font=[UIFont systemFontOfSize:12];
            
            _unReadLabel.textColor=[UIColor redColor];
            
            _unReadLabel.layer.cornerRadius=15;
            
            _unReadLabel.layer.borderWidth=1;
            
            _unReadLabel.layer.borderColor=[UIColor redColor].CGColor;
            
            _unReadLabel.textAlignment=1;
            
            [self.contentView addSubview:_unReadLabel];

        }
        
    }
    
    return self;
    
    
}

-(void)changeSwith:(UISwitch*)gestureSwith{
    if (_swithClickBlock) {
        
        _swithClickBlock(gestureSwith);
        
    }

}

-(void)layoutSubviews{
    
    [super layoutSubviews];
    
    if ([_reuseIdentifier isEqualToString:@"cell0"])  {
        
        if ([YPShareAccountInfo shareAccountInfo].token == nil) {
            
            _nameLabel.text = @"用户名";
            _headerImageView.image = [UIImage imageNamed:@"xcl"];
            
        }else{
            
            NSLog(@"userName=%@",[YPShareAccountInfo shareAccountInfo].userName);
            _nameLabel.text =[YPShareAccountInfo shareAccountInfo].userName;
            
            [_headerImageView sd_setImageWithURL:[NSURL URLWithString:[YPShareAccountInfo shareAccountInfo].avatar] placeholderImage:[UIImage imageNamed:@"xcl"]];

        }

    }
    
    if ([_reuseIdentifier isEqualToString:@"cell1"]) {
        
        BOOL hasPwd = [CLLockVC hasPwd];

            if (hasPwd) {
        
                [_gestureSwith setOn:YES];
        
            }else{
        
                [_gestureSwith setOn:NO];
                
            }
        
    }
    

}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
